<?php
/**
 * create by phpstorm
 * User: 冰帝
 * Date: 2023/5/4
 * Remark: 登录接口
 * 现在的努力是为了小时候吹过的牛逼
 */

namespace app\wechat\controller;


use think\facade\Db;
use think\facade\Cache;
use think\exception\ValidateException;
class Login extends AuthBase
{

    public function register_teacher(){
        $data=input('post.');
        try {
            validate(\app\common\validate\Record::class)
                ->scene("register_teacher")
                ->check($data);
        } catch (ValidateException $e) {
            // 验证失败 输出错误信息
            return $this->show(0, $e->getError());
        }
        $user=Db::name('user')->where(['id'=>$this->userId,'type'=>1])->find();
        if(!$user){
            return show(0,'此身份状态无法注册');
        }
        $res=Db::name('user')->where('id',$this->userId)->update([
            'nickname'=>$data['nickname'],
            'edu'=>$data['edu'],
            'strong_point'=>$data['strong_point'],
            'type'=>4,
        ]);
        if(!$res){
            return show(0,'注册失败,请重试');
        }
        $cachedValue['uid'] = $this->userId;
        $cachedValue['userType'] = 4;
        Cache::set($this->accessToken,serialize($cachedValue),2592000);
        return show(1,'注册成功');
    }
}